package com.wcl.demo.db;

import com.wcl.demo.model.entity.User;
import com.wcl.demo.model.entity.UserDao;

import java.util.List;

/**
 * Created by dllo on 15/11/20.
 */
public class UserHelper {
    private DaoSingleton instance = DaoSingleton.getInstance();
    private UserDao userDao;

    public UserHelper() {
        this.userDao = instance.getUserDao();
    }

    /***
     * 添加数据
     */

    public void saveUser(List<User> users){
        userDao.insertInTx(users);
    }

    /***
     * 删除数据
     */
    public void deleteUser(List<User> users ){
        userDao.deleteAll();
    }

    /***
     * 查询所有
     */

    public List<User> queryAllUser(){

        return userDao.loadAll();
    }

    /***
     * 按用户名进行查询
     */

    public List<User> queryByUserName(String name){
        List<User> list = userDao.queryBuilder().where(UserDao.Properties.Username.eq(name)).list();
        return list;
    }
}
